using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class StrawShoot : MonoBehaviour
{
    public GameObject warning;
    public GameObject warningP;
    public GameObject FireBall;
    public bool IsUp = true;
    private float atkcd = 0f;
    // Start is called before the first frame update
    void Start()
    {
        warningP = GameObject.Find("Canvas").transform.gameObject;

    }

    // Update is called once per frame
    void Update()
    {
        if (atkcd >= 0)
            atkcd -= Time.deltaTime;
    }

    private void OnTriggerStay(Collider other)
    {
        if (other.gameObject.tag == "Player"&&atkcd<=0)
        {
            atkcd = 4.5f;
            GameObject warn = Instantiate(warning);
            warn.transform.SetParent(warningP.transform);   
            warn.transform.position = transform.position + transform.up * -1.5f;
            if(IsUp==true)
            warn.transform.Rotate(Vector3.up, 90f);
            Invoke("shoot", 1f);
        }
    }

    void shoot()
    {
        GameObject bullet = Instantiate(FireBall);
        bullet.transform.SetParent(warningP.transform);
        bullet.transform.position = transform.position;
        if (IsUp == true)
            bullet.transform.Rotate(Vector3.up, 90f);
    }
}
